package cn.tedu.mall.front.controller;

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.common.restful.JsonResult;
import cn.tedu.mall.front.service.IFrontSpuService;
import cn.tedu.mall.pojo.product.vo.SpuListItemVO;
import cn.tedu.mall.pojo.product.vo.SpuStandardVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/front/spu")
public class FrontSpuController {

    private final IFrontSpuService frontSpuService;

    public FrontSpuController(IFrontSpuService frontSpuService) {
        this.frontSpuService = frontSpuService;
    }

    /**
     * 根据categoryId查询spu列表
     */
    @GetMapping("/list/{categoryId}")
    public JsonResult<JsonPage<SpuListItemVO>> spuList(
            @PathVariable("categoryId") Long categoryId,
            Integer page,
            Integer pageSize) {
        JsonPage<SpuListItemVO> jsonPage = frontSpuService.listSpuByCategoryId(categoryId, page, pageSize);
        return JsonResult.ok(jsonPage);
    }

    /**
     * 根据spuId查询spu列表
     */
    @GetMapping("/{id}")
    public JsonResult<SpuStandardVO> spuStandardList(@PathVariable("id") Long id) {
        SpuStandardVO spuStandardVO = frontSpuService.getFrontSpuById(id);
        return JsonResult.ok(spuStandardVO);
    }

}
